package org.dandsoft.blackbox.utils.list;

/**
 * @author Vilyuzhanin Denis (Fin)
 */
public class ListElementIterator<Element> {

    private ListElement<Element> start;
    private ListElement<Element> current;

    public ListElementIterator(ListElement<Element> start) {
        if (start == null) {
            throw new NullPointerException("Start element can not be null");
        }
        this.start = start;
    }

    public ListElement<Element> getCurrent() {
        return current;
    }

    public boolean hasNextRight() {
        return !(current != null && current.getRight() == null) || (current == null && start != null);
    }

    public ListElement<Element> nextRight() {
        if (hasNextRight()) {
            if (current == null) {
                return current = start;
            } else {
                return current = current.getRight();
            }
        } else {
            return null;
        }
    }

   


}
